package cloud.maque.module.system.service.impl;


import cloud.maque.module.system.entity.SysRolePrivilege;
import cloud.maque.module.system.mapper.RolePrivilegeMapper;
import cloud.maque.module.system.service.RolePrivilegeService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RolePrivilegeServiceImpl extends ServiceImpl<RolePrivilegeMapper, SysRolePrivilege> implements RolePrivilegeService {
    @Override
    public List<SysRolePrivilege> GetList(SysRolePrivilege data) {
        QueryWrapper<SysRolePrivilege> query = new QueryWrapper<>();
        if (!StrUtil.isEmptyIfStr(data.getRoleId())) {
            query.lambda().eq(SysRolePrivilege::getRoleId, data.getRoleId());
        }
        if (!StrUtil.isEmptyIfStr(data.getPrivilegeId())) {
            query.lambda().like(SysRolePrivilege::getPrivilegeId, data.getPrivilegeId());
        }
        return this.list(query);
    }

    @Override
    public SysRolePrivilege SaveRolePrivilege(SysRolePrivilege data) {
        this.saveOrUpdate(data);
        return data;
    }

    @Override
    public Boolean DeleteByRoleId(String roleId) {
        QueryWrapper<SysRolePrivilege> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysRolePrivilege::getRoleId, roleId);
        return this.remove(queryWrapper);
    }

    @Override
    public Boolean DeleteByPrivilegeId(String PrivilegeId) {
        QueryWrapper<SysRolePrivilege> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysRolePrivilege::getPrivilegeId, PrivilegeId);
        return this.remove(queryWrapper);
    }
}
